<?php

class DB_MysqlStatement {
    public $result;
    public $query;
    public $binds;
    
    public function __construct($dbh, $query) {
        $this->query = $query;
        if (!is_resource($dbh)) throw new exception("La conexi&oacute; no es valida");
        
        // Executem la query
        $query = $this->query;
        $query = mysql_real_escape_string($query);
        $this->result = mysql_query($query, $dbh);
        if (!$this->result) throw new exception("La operaci&oacute; era una inserci&oacute; o la consulta no ha retornat res.");     
        
    }
    
    public function fetch_row() {
        if (!$this->result) throw new exception("La consulta no s'ha executat.");
    }
    
    public function fetch_assoc() {
        return mysql_fetch_assoc($this->result);
    }
    
    public function fetchall_assoc() {
        $retval[] = array();
        while ($row = $this->fetch_assoc()) $retval[] = $row;
        return $retval;
    }

}

?>

